<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="<%=basePath %>/css/updateVideo.css"/>
    <link rel="stylesheet" href="<%=basePath %>/css/list.css">
    <link href="<%=basePath %>/css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link href="<%=basePath %>/css/formsCSS.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath %>/css/simditor.css"/>

    <!-- select start -->
    <link href="<%=basePath %>/lib/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <link href="<%=basePath %>/css/multiple-select.css" rel="stylesheet" type="text/css"/>
    <!-- select end -->

    <script src="<%=basePath%>/lib/My97DatePicker/WdatePicker.js"></script>
    <script src="<%=basePath %>/js/jquery.min.js"></script>
    <script src="<%=basePath %>/js/formsJS.js"></script>
    <script src="<%=basePath %>/js/jquery.form.js"></script>
    <script type="text/javascript" src="<%=basePath %>/js/module.js"></script>
    <script type="text/javascript" src="<%=basePath %>/js/hotkeys.js"></script>
    <script type="text/javascript" src="<%=basePath %>/js/uploader.js"></script>
    <script type="text/javascript" src="<%=basePath %>/js/simditor.js"></script>
    <script type="text/javascript" src="<%=basePath %>js/H-ui.js"></script>
    <script type="text/javascript" src="<%=basePath %>js/laydate/laydate.js"></script>
    <script src="<%=basePath%>/js/multiple-select.js"></script>
    <!-- kindeditor富文本编辑器 -->
    <link href="<%=basePath%>/kindeditor/themes/default/default.css">
    <link href="<%=basePath%>/kindeditor/plugins/code/prettify.css">
    <script src="<%=basePath%>/kindeditor/lang/zh-CN.js"></script>
    <script src="<%=basePath%>/kindeditor/kindeditor-all.js"></script>

    <script type="text/javascript">


        //选中下拉框选择的值
        function choice() {
            var type = document.getElementById('type').value;
            if (type == 1) {
                $("#divcourseId").show();
                $("#divcardId").hide();
            } else if (type == 3) {
                $("#divcourseId").hide();
                $("#divcardId").show();
            } else {
                $("#divcourseId").hide();
                $("#divcardId").hide();
            }
        };
    </script>
</head>
<body>
<div class="connect_wrap">
    <h3 style="text-align: center;">增加编辑团购活动</h3>
    <div class="row cl" style="max-width:88%;margin-left:8%;">
        <div class="labelText"></div>
        <form id="configForm" method="post"
              enctype="multipart/form-data" action="<%=basePath %>groupbuying/addOrUpdateActivity">
            <div class="col-sm-4"></div>
            <div class="col-sm-4">
                <div class="boxs">
                    <input type="hidden" name="id" value="${activity.id}">
                    <input type="text" class="inputBox" placeholder="活动名称" name="name" value="${activity.name}">
                    <input type="number" class="inputBox" placeholder="限制人数" name="num" value="${activity.num}">
                    <input type="text" class="inputBox" placeholder="拼团价格" name="collagePrice"
                           value="${activity.collagePrice}">
                    <input type="text" class="inputBox" placeholder="课程原价" name="originPrice"
                           value="${activity.originPrice}">
                    <input type="text" class="inputBox" placeholder="活动价格" name="activityPrice"
                           value="${activity.activityPrice}">
                    <input type="text" class="inputBox" placeholder="团长价格" name="leaderPrice"
                           value="${activity.leaderPrice}">
                    <input type="text" class="inputBox" placeholder="拼团限时（小时）" name="longTime"
                           value="${activity.longTime}">
                    <input type="text" class="inputBox" placeholder="备注" name="remark" value="${activity.remark}">
                    <div style="width:90%;margin-top:30px;">
                        <div class="labelText" style="position: relative; left: 0px; color: rgb(154, 144, 144);">课程类别
                        </div>
                        <select id="type" name="type" class="selectBox" onchange="choice()"
                                required="required">
                            <!--  	<option value="">分类</option>  -->
                            <option value="1" ${activity.type == 1 ? 'selected="selected"' : '' }>课程
                            </option>
                            <option value="3" ${activity.type == 3 ? 'selected="selected"' : '' }>课程包
                            </option>
                        </select>
                    </div>
                    <div style="width:90%;margin-top:30px" id="divcourseId">
                        　
                        <div class="labelText" style="position: relative; left: 0px; color: rgb(154, 144, 144);">选择课程
                        </div>

                        <select id="courseIds" name="courseId" class="selectBox">
                            <c:forEach items="${courses}" var="c">
                                <option value="${c.id}" ${activity.type == 1 and c.id == activity.foreignId ? 'selected="selected"' : ''}>${c.id}:${c.courseName}</option>
                            </c:forEach>
                        </select>
                    </div>

                    <div style="width:90%;margin-top:30px;display:none;" id="divcardId">
                        <div class="labelText" style="position: relative; left: 0px; color: rgb(154, 144, 144);">选择课程包
                        </div>

                        <select id="cardIds" name="cardId" class="selectBox">
                            <c:forEach items="${cards}" var="c">
                                <option value="${c.id}" ${activity.type == 3 and c.id == activity.foreignId ? 'selected="selected"' : ''}>${c.id}:${c.cardName}</option>
                            </c:forEach>
                        </select>
                    </div>

                    <div style="width:90%;margin-top:30px;">
                        <div class="labelText" style="position: relative; left: 0px; color: rgb(154, 144, 144);">有效日期
                        </div>
                        <input name="rangeTime" type="text" class="inputBox" id="date" readonly="readonly"
                               value="<c:if test="${not empty activity.startDate}">${activity.startDate} - ${activity.endDate}</c:if>">
                    </div>
                    <input type="text" class="inputBox" placeholder="活动标题" name="title" value="${activity.title}">
                    <input type="text" class="inputBox" placeholder="活动副标题" name="subtitle"
                           value="${activity.subtitle}">
                    <input type="file" class="inputBox" placeholder="活动图片" name="imgFile"
                           value="${activity.img}" onchange="img1()" id="img"/>
                    <br/><br/><img src="${WF_CONSOLE_CONFIG_OSS_URL}${activity.img}" id="lowImg" width="320"
                                   height="180"
                                   <c:if test="${empty activity.img}">style="display: none;"</c:if> />
                    <input type="file" class="inputBox" placeholder="活动缩略图" name="subimgFile"
                           value="${activity.subimg}" onchange="subimg1()" id="subimg"/>
                    <br/><br/><img src="${WF_CONSOLE_CONFIG_OSS_URL}${activity.subimg}" id="highImg" width="180"
                                   height="180"
                                   <c:if test="${empty activity.subimg}">style="display: none;"</c:if> />
                    <input type="file" class="inputBox" placeholder="分享图片" name="shareFile"
                           value="${activity.shareImg}" onchange="shareFunc()" id="shareImg"/>
                    <br/><br/><img src="${WF_CONSOLE_CONFIG_OSS_URL}${activity.shareImg}" id="shareShow" width="180"
                                   height="320"
                                   <c:if test="${empty activity.shareImg}">style="display: none;"</c:if> />
                    <textarea id="details" placeholder="活动介绍" name="details" class="inputBox kindeditor"
                              style="width: 90%;">${activity.details}</textarea>
                    <textarea id="syllabus" placeholder="课程表" name="syllabus" class="inputBox kindeditor"
                              style="width: 90%;">${activity.syllabus}</textarea>
                    <textarea id="notes" placeholder="拼团须知" name="notes" class="inputBox kindeditor"
                              style="width: 90%;">${activity.notes}</textarea>
                    <div style="width:90%;margin-top:30px;">
                        <div class="labelText" style="position: relative; left: 0px; color: rgb(154, 144, 144);">活动类别
                        </div>
                        <select name="activityType" class="selectBox">
                            <option value="1" ${activity.activityType == 1 ? 'selected="selected"' : '' }>拉新</option>
                            <option value="2" ${activity.activityType == 2 ? 'selected="selected"' : '' }>促销</option>
                        </select>
                    </div>
                    <div style="width:90%;margin-top:30px;">
                        <div class="labelText" style="position: relative; left: 0px; color: rgb(154, 144, 144);">活动状态
                        </div>
                        <select id="statusSelect" name="status" class="selectBox">
                            <option value="1" ${activity.status == 1 ? 'selected="selected"' : '' }>上线</option>
                            <option value="2" ${activity.status == 2 ? 'selected="selected"' : '' }>下线</option>
                        </select>
                    </div>
                    <input type="submit" value="确定" class="true"/>
                    <input type="button" class="false" value="取消" onclick="window.history.go(-1)">
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">

    $(function () {
        laydate.render({
            elem: '#date'
            , type: 'datetime'
            , range: true
        });
    });

    $(function () {
        var type = document.getElementById('type').value.trim();
        if (type == 1) {
            $("#divcourseId").show();
            $("#divcardId").hide();
        } else if (type == 3) {
            $("#divcourseId").hide();
            $("#divcardId").show();
        } else {
            $("#divcourseId").show();
            $("#divcardId").hide();
        }
    });

    function img1() {
        var url = window.URL.createObjectURL($("#img")[0].files[0]);
        $("#lowImg").attr('src', url);
        $("#lowImg").css("display", "");
    };

    function subimg1() {
        var url = window.URL.createObjectURL($("#subimg")[0].files[0]);
        $("#highImg").attr('src', url);
        $("#highImg").css("display", "");
    };

    function shareFunc() {
        var url = window.URL.createObjectURL($("#shareImg")[0].files[0]);
        $("#shareShow").attr('src', url);
        $("#shareShow").css("display", "");
    };


    var editor;
    KindEditor.ready(function (K) {

        editor = K.create('#details', {
            uploadJson: '<%=basePath%>kindeditor/upload',
            fillDescAfterUploadImage: false,
            allowImageRemote: false,
            afterCreate: function () {
                var self = this;
                K.ctrl(document, 13, function () {
                    self.sync();
                });
                K.ctrl(self.edit.doc, 13, function () {
                    self.sync();
                });
            },
            afterBlur: function () {
                this.sync();
            }
        });
    });

    var syllabusEditor;
    KindEditor.ready(function (K) {

        syllabusEditor = K.create('#syllabus', {
            uploadJson: '<%=basePath%>kindeditor/upload',
            fillDescAfterUploadImage: false,
            allowImageRemote: false,
            afterCreate: function () {
                var self = this;
                K.ctrl(document, 13, function () {
                    self.sync();
                });
                K.ctrl(self.edit.doc, 13, function () {
                    self.sync();
                });
            },
            afterBlur: function () {
                this.sync();
            }
        });
    });

    var notesEditor;
    KindEditor.ready(function (K) {

        notesEditor = K.create('#notes', {
            uploadJson: '<%=basePath%>kindeditor/upload',
            fillDescAfterUploadImage: false,
            allowImageRemote: false,
            afterCreate: function () {
                var self = this;
                K.ctrl(document, 13, function () {
                    self.sync();
                });
                K.ctrl(self.edit.doc, 13, function () {
                    self.sync();
                });
            },
            afterBlur: function () {
                this.sync();
            }
        });
    });
</script>

</html>